<?php 
namespace App\Services;

use Gloudemans\Shoppingcart\Facades\Cart;

/**
 * UpdateQtyService
 */
class UpdateQtyService
{
    public function setQtyCount($rowId, $type, $qty, $stock)
    {
        switch ($type) {

            case 2:
                 Cart::update($rowId, request()->qty);
                
                return response()->json(['status'=>'change','subtotal'=>Cart::subtotal(),'count'=>Cart::count(),'tax'=>0], 200);
                break;
            case 0:

                 Cart::update($rowId, request()->qty+=1);

                 return response()->json(['status'=>'plus','subtotal'=>Cart::subtotal(),'count'=>Cart::count(),'tax'=>0], 200);
                break;
            case 1:
                 
                 Cart::update($rowId, request()->qty-=1);
                 if (request()->qty == 0) {
                     return response()->json(['status'=>'null','subtotal'=>Cart::subtotal(),'count'=>Cart::count(),'tax'=>0], 200);
                 }
                 return response()->json(['status'=>'ajan','subtotal'=>Cart::subtotal(),'count'=>Cart::count(),'tax'=>0], 200);
                break;
            
            default:
                echo 'null';
                break;
        }
    }
}
